package week5.day30;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

/**
 * @Author fengzihao
 * @Date 2024-05-14 20:12
 */
public class StudentManager {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("请输入学生的姓名：");
            String name = scanner.nextLine();
            if (name==null){
                System.out.println("输入的姓名不能为空，请重新输入");
                continue;
            }
            Student student = new Student(name);
            students.add(student);
            System.out.println("请选择是否要删除某个学生：");
            String deleteTag = scanner.nextLine();
            if ("是".equals(deleteTag)){
                System.out.println("请输入要删除学生的名字");
                String deleteName = scanner.nextLine();
                Iterator<Student> iterator = students.iterator();
                while (iterator.hasNext()) {
                    Student student1 = iterator.next();
                    if (student1.name.equals(deleteName)) {
                        iterator.remove();
                    }
                }
            }
            System.out.println("是否要显示当前学生名单：");
            String printTag = scanner.nextLine();
            if ("是".equals(printTag)){
                System.out.println(students);
            }
            System.out.println("是否要退出执行：");
            String exitTag = scanner.nextLine();
            if ("是".equals(exitTag)){
                break;
            }
        }
    }
}
class Student{
    String name;

    public Student(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                '}';
    }
}
